﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace EmailMarketingCampaign
{
    public partial class MaintainMember : System.Web.UI.Page
    {
        RecordControl rc = new RecordControl();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                int rowsCount = GridView1.Rows.Count;

                for (int i = 0; i < rowsCount; i++)
                {
                    string ID = GridView1.DataKeys[i].Value.ToString();


                    (((DropDownList)this.GridView1.Rows[i].Cells[3].FindControl("drGroup1"))).SelectedValue = rc.getGroupValue("group1", ID);
                    (((DropDownList)this.GridView1.Rows[i].Cells[4].FindControl("drGroup2"))).SelectedValue = rc.getGroupValue("group2", ID);
                    (((DropDownList)this.GridView1.Rows[i].Cells[5].FindControl("drGroup3"))).SelectedValue = rc.getGroupValue("group3", ID);

                }
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            int rowsCount = GridView1.Rows.Count;

            for (int i = 0; i < rowsCount; i++)
            {


                string MemberID = GridView1.DataKeys[i].Value.ToString();

                int group1 = int.Parse((((DropDownList)this.GridView1.Rows[i].Cells[3].FindControl("drGroup1"))).SelectedValue);
                int group2 = int.Parse((((DropDownList)this.GridView1.Rows[i].Cells[4].FindControl("drGroup2"))).SelectedValue);
                int group3 = int.Parse((((DropDownList)this.GridView1.Rows[i].Cells[5].FindControl("drGroup3"))).SelectedValue);

                rc.UpdateGroupRecord(group1, group2, group3, MemberID);

            }


        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");

                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
            }

        }
    }
}
